﻿package rd.hardcore.datas 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	import rd.debug.Debug;
	
	/**
	 * Track Data Format
	 * @author Romain Prache
	 */
	public class Track extends EventDispatcher
	{
		/* VAR */
		private var _keyId		: int;
		private var _file		: String = "";
		private var _thumb		: String = "";
		private var _desc		: String = "";
		//private var _position	: Point;
		
		/*	Compte le nombre de fois que le pads est joué	*/
		private var _cpt		: int;
		
		public function Track() 
		{
			
		}
		
		public function build ( node : XML ) : void
		{
			keyId 	= int( node.@keyId.toString() );
			file	= node.@file.toString();
			thumb	= node.@pad_thumb.toString();
			desc	= node.toString();
		/*	if (node.@x) {
				_position = new Point(node.@x, node.@y);
			}*/
			genChild();
		}

		/**
		 * Permets de prevenir son Pads d'affichage de son changement détat
		 */
		public function updateSoRefresh():void
		{
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		public function genChild():XML
		{
			desc = file.replace(".wav", "");
			desc = desc.replace(".mp3", "");
			desc = desc.replace("medias/songs/", "");
			var child:XML = new XML("<track keyId=\"" + keyId + "\" file=\"" + file + "\" pad_thumb=\"" + thumb + "\"><![CDATA[" + desc + "]]></track>") ;
			return child;
		}
		
		public function get cpt():int { return _cpt; }
		
		public function set cpt(value:int):void 
		{
			_cpt = value;
		}
		
		public function get keyId():int { return _keyId; }
		
		public function set keyId(value:int):void 
		{
			_keyId = value;
		}
		
		public function get file():String { return _file; }
		
		public function set file(value:String):void 
		{
			_file = value;
		}
		
		public function get thumb():String { return _thumb; }
		
		public function set thumb(value:String):void 
		{
			_thumb = value;
		}
		
		public function get desc():String { return _desc; }
		
		public function set desc(value:String):void 
		{
			_desc = value;
		}
		
		/*public function get position():Point { return _position; }
		
		public function set position(value:Point):void 
		{
			_position = value;
		}*/
		
	}
	
}